package com.ruoyi.system.controller;


import com.ruoyi.system.annotation.UserContext;
import com.ruoyi.system.common.Result;
import com.ruoyi.system.domain.vo.UserData;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/myMerchant")
public class GetMerchantIdController  {

    @PostMapping("/getMerchantId")
    public Result getMerchantId() {
        // 使用 userData
        try {
            UserData userData = UserContext.getUserData();

            int merchantId = userData.getMerchantId();

            int storeId = userData.getStoreId();

            Map<String, Object> map = new HashMap<>();
            map.put("merchantId", merchantId);
            map.put("storeId", storeId);

            return Result.success(map);
        }finally {
            // 清理上下文，确保即使发生异常也能执行清理
            UserContext.clear();
        }

    }
}
